<?php

namespace App\Models\Wechat;

use Illuminate\Database\Eloquent\Model;

use Cache;

class Image extends Model
{
    protected $table = 'wechat_image';

    //缓存过期时间
    protected $cacheTime = 86400*7;

    public function cacheFind($id){
    	$image = Cache::get(config('app.name').':image:'.$id);
    	if(!$image){
    		$image = $this->find($id);
    		if(!$image){
    			return false;
    		}
    		Cache::put(config('app.name').':image:'.$id, $image,$this->cacheTime);
    	}
    	return $image;
    }

    public function cacheEmpty($id){
        Cache::forget(config('app.name').':image:'.$id);
        return $this;
    }
}
